<?php 
header('Content-Type:text/html;charset=gbk');
require_once("db_manage.php");
$title = $_POST['route_travel_title'];
$area = $_POST['route_travel_area'];
$days = $_POST['days'];
$routeid = $_POST['routeid'];
$travelid = $_POST['route_travel_id'];
$tijiao = $_POST['tijiao'];
$postuser = $_POST['routepostuser'];
$len_travel = count($days);	

// echo "<br>routeid:".$routeid;

if($routeid==""){
	$sql = "insert into pcd_route(state,postuser,timestamp) values(0,'".$postuser."',now())";
	//echo "<br>sql:".$sql;
	mysql_query($sql);
	$result_id = getLastId();
	while($rs=mysql_fetch_object($result_id)){	
		$lastid = $rs->id;	
	}
	
//echo "<br>lastid:".$lastid;
	if($days[0]==""){
		$days[0] = 0;
	}	
	$tijiaoid = $lastid;	
}else{	
	$sql = "delete from pcd_travel_route where routeid = ".$routeid;
	mysql_query($sql);
	$tijiaoid = $routeid;
}

//echo "<br>len:".$len_travel."  tijiaoid=".$tijiaoid;

for($i=0;$i<$len_travel;$i++){
	$sql = "insert into pcd_travel_route(routeid,travelid,travelname,days,area,postuser,timestamp) values(".$tijiaoid.",".$travelid[$i].",'".$title[$i]."',".$days[$i].",'".$area[$i]."','".$postuser."',now())";
//	echo "<br>sql len_travel:".$sql;
	mysql_query($sql);
}

if($tijiao=='tijiao'){
	$sql = "update pcd_route set state = 1 where rid = ".$tijiaoid;
	mysql_query($sql);	
	echo "<script>location.href='route_add.php?route_travel_title=".$title."&route_travel_area=".$area."&days=".$days."&routeid=".$routeid."';</script>";	
}
echo "<script>location.href='travel_detail.php?id=".$travelid[0]."';</script>";
?>
